package com.share.tool.mock.web;

import com.share.common.common.Page;
import com.share.common.common.Result;
import com.share.tool.mock.model.db.SourceConf;
import com.share.tool.mock.model.vo.SourceConfAddOrUpdateReq;
import com.share.tool.mock.model.vo.SourceConfPageReq;
import com.share.tool.mock.service.ISourceConfService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 触发参数配置  前端控制器
 * </p>
 *
 * @author author
 * @since 2023-11-24
 */
@RestController
@RequestMapping("/sourceconf")
public class SourceConfController {
    @Autowired
    private ISourceConfService sourceConfService;

    //分页查询
    @ResponseBody
    @RequestMapping(value = "/pageList")
    public Result httpPageList(SourceConfPageReq req) {
        Page page = sourceConfService.pageList(req);
        return Result.success(page);
    }

    @ApiOperation("新增")
    @RequestMapping("/add")
    public Result add(SourceConfAddOrUpdateReq req) {
        SourceConf record = new SourceConf();
        BeanUtils.copyProperties(req, record);
        return Result.bool(sourceConfService.save(record));
    }

    @ApiOperation("修改")
    @RequestMapping("/update")
    public Result update(SourceConfAddOrUpdateReq req) {
        if (req.getId() == null) {
            return Result.failure("参数异常!");
        }
        SourceConf record = new SourceConf();
        BeanUtils.copyProperties(req, record);
        return Result.bool(sourceConfService.updateById(record));
    }

    @ApiOperation("删除")
    @RequestMapping("/delete")
    public Result delete(Integer id) {
        return Result.bool(sourceConfService.removeById(id));
    }

}
